package com.flexcloudsdk.managers;
import java.io.IOException;
import java.util.logging.Logger;
import com.google.appengine.api.NamespaceManager;


@SuppressWarnings("unused")
public class CloudNamespaceManager {
	private String namespace;
	private String cloudNamespace;
	private static final Logger log = Logger.getLogger(CloudNamespaceManager.class.getName());
	private String sourceMethod;
	private String sourceClass;

	public CloudNamespaceManager() {
		log.info("CloudNamesapceManager has been created by BlazeDS");
		sourceMethod = Thread.currentThread().getStackTrace()[1].getMethodName().toString();
		sourceClass = CloudNamespaceManager.class.getName();

		namespace = NamespaceManager.get();
		cloudNamespace = NamespaceManager.getGoogleAppsNamespace();
	}

	public void setString(String value) {
		sourceMethod = Thread.currentThread().getStackTrace()[1].getMethodName().toString();
		log.info("Executing: " + sourceClass + "." + sourceMethod);

		NamespaceManager.set(value);
	}
	
	public boolean validate(String value) {
		sourceMethod = Thread.currentThread().getStackTrace()[1].getMethodName().toString();
		log.info("Executing: " + sourceClass + "." + sourceMethod);

		boolean flag  = false;
		try {
			NamespaceManager.validateNamespace(value);
			flag = true;
		} catch (IllegalArgumentException exception) {
			flag = false;
		}	
		return flag;
	}
	
	public String getCurrent() {
		sourceMethod = Thread.currentThread().getStackTrace()[1].getMethodName().toString();
		log.info("Executing: " + sourceClass + "." + sourceMethod);

		return namespace;
	}
	
	public String getCloudNamespace() {
		sourceMethod = Thread.currentThread().getStackTrace()[1].getMethodName().toString();
		log.info("Executing: " + sourceClass + "." + sourceMethod);

		return cloudNamespace;
	}
}
